package com.lanhe.game.tixian.controller;

import com.lanhe.common.annotation.Log;
import com.lanhe.common.constant.Constants;
import com.lanhe.common.core.controller.BaseController;
import com.lanhe.common.core.domain.AjaxResult;
import com.lanhe.common.core.page.TableDataInfo;
import com.lanhe.common.enums.BusinessType;
import com.lanhe.common.utils.poi.ExcelUtil;

import com.lanhe.game.sysAppUser.domain.SysAppUser;
import com.lanhe.game.sysAppUser.service.ISysAppUserService;
import com.lanhe.game.tixian.domain.LhGameSq;
import com.lanhe.game.tixian.service.ILhGameSqService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/game/lhgamesq")
public class LhGameSqController extends BaseController {


    /**
     * 服务对象
     */
    @Resource
    private ILhGameSqService iLhGameSqService;

    @Resource
    private ISysAppUserService iSysAppUserService;

    /**
     * 分页查询所有数据
     */
    @GetMapping("/list")
    public TableDataInfo list(LhGameSq lhGameSq) {
        startPage();
        List<LhGameSq> lists = iLhGameSqService.selectGameList(lhGameSq);
        for (LhGameSq list : lists) {
            list.setAuditStatusName(Constants.OrdersWithdrawalStatus.getOrdersWithdrawalStatusName(list.getAuditStatus()));
            list.setPayedName(Constants.OrdersPayedStatus.getOrdersPayedStatusName(list.getPayed()));
        }
        return getDataTable(lists);
    }

    /**
     * 根据ID查询订单
     *
     * @param orderId id
     * @author zhanggl
     * @date 2024年01月05日22:02:11
     */
    @GetMapping(value = {"/", "/{orderId}"})
    public AjaxResult getInfo(@PathVariable(value = "orderId") Long orderId) {
        LhGameSq lhGameSq = iLhGameSqService.selectOrdersWithdrawalById(orderId);
        lhGameSq.setAuditStatusName(Constants.OrdersWithdrawalStatus.getOrdersWithdrawalStatusName(lhGameSq.getAuditStatus()));
        lhGameSq.setAuditStatusName(Constants.OrdersPayedStatus.getOrdersPayedStatusName(lhGameSq.getPayed()));
        return success(lhGameSq);
    }

    /**
     * 审核通过
     *
     * @author zhanggl
     * @date 2024年01月05日22:02:16
     */
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody LhGameSq ordersWithdrawal) {
        if (ObjectUtils.isEmpty(ordersWithdrawal.getOrderId())){
            return error("主键ID不能为空");
        }
        return toAjax(iLhGameSqService.auditOrdersWithdrawalById(ordersWithdrawal));
    }

    /**
     * 设为已付款
     *
     * @author zhanggl
     * @date 2024年01月05日22:35:58
     */
    @PostMapping("/setPayed")
    public AjaxResult setPayed(@RequestBody LhGameSq lhGameSq) {
        if (ObjectUtils.isEmpty(lhGameSq.getOrderId())){
            return error("主键ID不能为空");
        }
        return toAjax(iLhGameSqService.setPayed(lhGameSq));
    }

    /**
     * 提现申请
     *
     * @author zhanggl
     * @date 2024年01月05日22:43:10
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody LhGameSq ordersWithdrawal) {
        SysAppUser sysAppUser = iSysAppUserService.selectAppuserId(ordersWithdrawal.getWxId());
        ordersWithdrawal.setMemberId(sysAppUser.getAppUserId());
        return toAjax(iLhGameSqService.insertOrdersWithdrawa(ordersWithdrawal));
    }

    /**
     * 导出提现订单
     */
    @Log(title = "提现订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LhGameSq lhOrdersWithdrawal)
    {
        System.err.println("lhOrdersWithdrawal查询内容 "+ lhOrdersWithdrawal);
        List<LhGameSq> lists = iLhGameSqService.selectGameList(lhOrdersWithdrawal);
        System.err.println("list "+lists);
        ExcelUtil<LhGameSq> util = new ExcelUtil<LhGameSq>(LhGameSq.class);
        util.exportExcel(response, lists, "用户提现表","支付宝批量付款文件");
    }
}
